package com.vornitologist.widgetset;

import java.util.ArrayList;
import java.util.Collection;

import com.vaadin.addon.touchkit.gwt.TouchKitWidgetMapGenerator;
import com.vaadin.terminal.Paintable;
import com.vaadin.ui.ClientWidget.LoadStyle;

/**
 * This customized widget map generator is used to get full control to optimize
 * the generated widgetset.
 */
public class WidgetMapGenerator extends TouchKitWidgetMapGenerator {

    @Override
    protected Collection<Class<? extends Paintable>> getUsedPaintables() {
        /*
         * Optimize widgetset by including only components which are actually
         * used in this app.
         * 
         * Hint: This list was initially is copied with debugger from
         * CommunicationManger. First click throught the app so that all
         * components have been shown. Then use debugger to see the collection
         * that CM keeps in memory (currentlyOpenWindowsInClient ->
         * OpenWindowCache).
         */
        ArrayList<Class<? extends Paintable>> a = new ArrayList<Class<? extends Paintable>>();
        a.add(com.vaadin.addon.touchkit.ui.Switch.class);
        a.add(com.vaadin.ui.Embedded.class);
        a.add(com.vaadin.addon.touchkit.ui.NumberField.class);
        a.add(com.vaadin.addon.touchkit.ui.EmailField.class);
        a.add(com.vaadin.ui.CssLayout.class);
        a.add(org.vaadin.vol.PointVector.class);
        a.add(org.vaadin.vol.VectorLayer.class);
        a.add(org.vaadin.vol.Popup.class);
        a.add(com.vaadin.addon.touchkit.ui.NavigationView.class);
        a.add(com.vaadin.addon.touchkit.ui.TabBarView.class);
        a.add(com.vaadin.ui.FormLayout.class);
        a.add(com.vaadin.ui.Link.class);
        a.add(com.vaadin.ui.NativeSelect.class);
        a.add(com.vaadin.ui.DateField.class);
        a.add(com.vaadin.addon.touchkit.ui.NavigationBar.class);
        a.add(com.vaadin.ui.Button.class);
        a.add(org.vaadin.vol.OpenStreetMapLayer.class);
        a.add(com.vaadin.addon.touchkit.ui.Popover.class);
        a.add(com.vaadin.ui.Window.class);
        a.add(org.vaadin.vol.OpenLayersMap.class);
        a.add(com.vaadin.ui.ComboBox.class);
        a.add(com.vaadin.ui.Form.class);
        a.add(com.vaadin.addon.touchkit.ui.NavigationButton.class);
        a.add(com.vaadin.ui.Table.class);
        a.add(com.vaadin.addon.touchkit.ui.NavigationManager.class);
        a.add(com.vaadin.ui.Label.class);
        a.add(com.vaadin.addon.touchkit.ui.VerticalComponentGroup.class);
        a.add(com.vaadin.ui.TextField.class);
        a.add(com.vaadin.ui.OptionGroup.class);
        
        a.add(com.vaadin.ui.HorizontalLayout.class);
        a.add(com.vaadin.ui.VerticalLayout.class);
        a.add(com.vaadin.ui.TextArea.class);
        
        return a;
    }

    @Override
    protected LoadStyle getLoadStyle(Class<? extends Paintable> paintableType) {
        /*
         * Eager method appears to load faster in mobile networks if widgetset
         * is otherwise optimized. Current 3G networks are rather fast to
         * transfer data, but latencies are large. Saved bytes are lost due to
         * increased negotioation with the server.
         * 
         * If the application has big components which are rarely used or not on
         * the initial views, it may be best to load those widgets eagerly or
         * lazily.
         */
        return LoadStyle.EAGER;
    }

}
